
package com.gitee.jmash.oidc.oauth2.models;

import com.gitee.jmash.common.utils.BasicAuthzUtil;
import com.gitee.jmash.oidc.oauth2.enums.GrantType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.HeaderParam;

/**
 * /oauth/token Model.
 *
 * @author CGD
 *
 */
public class TokenModel {

  @FormParam("grant_type")
  @NotNull
  private GrantType grantType;

  /** 客户端端身份认证. */
  @HeaderParam("Authorization")
  @NotBlank
  private String authorization;

  private String clientId;

  private String clientSecret;

  /** 授权码. */
  @FormParam("code")
  private String code;

  @FormParam("redirect_uri")
  private String redirectUri;

  /** 授权范围. */
  @FormParam("scope")
  private String scope;

  /** 刷新Token. */
  @FormParam("refresh_token")
  private String refreshToken;

  /** 资源所有者用户名. */
  @FormParam("username")
  private String username;

  /** 资源所有者密码. */
  @FormParam("password")
  private String password;

  public String getAuthorization() {
    return authorization;
  }

  /** Basic Authorization. */
  public void setAuthorization(String authorization) {
    this.authorization = authorization;
    String[] creds = BasicAuthzUtil.decodeBasicAuthz(authorization);
    if (creds != null && creds.length == 2) {
      this.clientId = creds[0];
      this.clientSecret = creds[1];
    }
  }

  public String getClientId() {
    return clientId;
  }

  public void setClientId(String clientId) {
    this.clientId = clientId;
  }

  public String getClientSecret() {
    return clientSecret;
  }

  public void setClientSecret(String clientSecret) {
    this.clientSecret = clientSecret;
  }

  public GrantType getGrantType() {
    return grantType;
  }

  public void setGrantType(GrantType grantType) {
    this.grantType = grantType;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getRedirectUri() {
    return redirectUri;
  }

  public void setRedirectUri(String redirectUri) {
    this.redirectUri = redirectUri;
  }

  public String getRefreshToken() {
    return refreshToken;
  }

  public void setRefreshToken(String refreshToken) {
    this.refreshToken = refreshToken;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getScope() {
    return scope;
  }

  public void setScope(String scope) {
    this.scope = scope;
  }

}
